#ifndef SIMPLETCPSOCKETDLL_H
#define SIMPLETCPSOCKETDLL_H

#include <QObject>
#include <QTcpSocket>
#include <qtcpserver.h>
#include <qtcpsocket.h>
#include <QString>

#include "simpletcpsocketdll_global.h"

#define maxCLIENTNUMBER 64

typedef struct SimpleTcpClientInfo{
   QString IP;
   int Port;
   QByteArray SendData;
   QByteArray RecvData;

   bool switch_connect;
   bool switch_disconnect;
   bool switch_close;
   bool switch_remove;
   bool switch_send;
   bool switch_receive;

   bool mark_connect;
   bool mark_sendbusy;
   bool mark_readbusy;
   bool mark_ready2read;

}SimpleTcpClientInfo;

class SIMPLETCPSOCKETDLLSHARED_EXPORT SimpleTcpSocketDLL : QObject{
Q_OBJECT
public:
    SimpleTcpSocketDLL();
    ~SimpleTcpSocketDLL();
public:
    int         TcpClientNumber;
    QTcpSocket* pTcpSocket[maxCLIENTNUMBER];
    SimpleTcpClientInfo* pSimpleTcpClientInfo[maxCLIENTNUMBER];

public:
    short SimpleTcpClientadd(const QString ip,const int port,int &Order);
    short SimpleTcpClientremove(const int Order);

    short SimpleTcpClientconnect(const int Order);
    short SimpleTcpClientDisconnect(const int Order);
    short SimpleTcpClientClose(const int Order);

    short SimpleTcpClientWriteData(const int Order, QByteArray Data);
    short SimpleTcpClientReadData(const int Order, QByteArray& Data);

    short SimpleTcpClientSendBusy(const int Order,bool& busy);
    short SimpleTcpClientRead2Read(const int Order,bool& ready);

    bool  isTcpClientConnectStatus(const int Order);
    bool  isTcpClientSendBusy(const int Order);
    bool  isTcpClientRead2Read(const int Order);

    void SimpleclientMainThreadLoopRun(short type);

private:
    /*********************************************************************/
    short pSimpleTcpClientInfoMarkInit(int Order);
    short pSimpleTcpClientInfoSwitchInit(int Order);
private:
    void SimpleclientMainThreadLoopRun_StateChange();
    void SimpleclientMainThreadLoopRun_Send();
    void SimpleclientMainThreadLoopRun_Receive();
};

#endif // SIMPLETCPSOCKETDLL_H
